﻿using BuildStatus.Web.Models;
using Microsoft.TeamFoundation.Build.Client;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BuildStatus.Web.BuildServer
{
    public class BuildDefinitionComparer : IComparer<BuildDefinition>
    {
        private const string InProgress = "InProgress"; // Microsoft.TeamFoundation.Build.Client.BuildStatus.InProgress

        public int Compare(BuildDefinition x, BuildDefinition y)
        {
            if (!string.IsNullOrEmpty(x.Name) && !string.IsNullOrEmpty(y.Name))
            {
                if (!char.IsDigit(x.Name[0]) && char.IsDigit(y.Name[0]))
                    return -1;

                if (char.IsDigit(x.Name[0]) && !char.IsDigit(y.Name[0]))
                    return 1;

                if (char.IsDigit(x.Name[0]) && char.IsDigit(y.Name[0]))
                    return -string.Compare(x.Name, y.Name);
            }

            return string.Compare(x.Name, y.Name);
        }
    }
}